/* **********************************************************
 * Copyright 2010 Dimitar Vangelovski
 *
 * This file is part of the Gens3 3D Engine.
 * 
 * The Gens3 3D Engine is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 * 
 * The Gens3 3D Engine is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with the Gens3 3D Engine; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA
 * **********************************************************/


#include "common.h"
#include "Material.h"
#include "SubMaterial.h"
#include "MapDiffuse.h"

CMaterial::CMaterial()
{
	m_strMaterialName = "noname";
	m_fMaterialTransparency = 0.0f;
	m_nNumSubMtls = 0;
	m_pMapDiffuse = NULL;
	m_SubMaterialList.clear();
	m_fMaterialShine = 0.0f;
	m_fMaterialShineStrength = 0.0f;
	m_fMaterialSelfIllum = 0.0f;
	m_MaterialAmbient = CColorRGB();
	m_MaterialDiffuse = CColorRGB();
	m_MaterialSpecular = CColorRGB();
}

CMaterial::CMaterial(const CMaterial &other)
{
	m_strMaterialName = other.GetMaterialName();
	m_fMaterialTransparency = other.GetMaterialTransparency();
	m_nNumSubMtls = other.GetNumSubMtls();
	m_pMapDiffuse = other.GetMapDiffuse();
	m_SubMaterialList = other.GetSubMaterialList();
	m_fMaterialShine = other.GetMaterialShine();
	m_fMaterialShineStrength = other.GetMaterialShineStrength();
	m_fMaterialSelfIllum = other.GetMaterialSelfIllum();
	m_MaterialAmbient = other.GetMaterialAmbient();
	m_MaterialDiffuse = other.GetMaterialDiffuse();
	m_MaterialSpecular = other.GetMaterialSpecular();
}

CMaterial::CMaterial(std::string strMatName, float fMatTrans, int nNumSubMtls, CMapDiffuse *pMapDif, float fMatShine, float fMatShStrength, float fMatSelfIllum, CColorRGB matAmbient, CColorRGB matDiffuse, CColorRGB matSpecular)
{
	m_strMaterialName = strMatName;
	m_fMaterialTransparency = fMatTrans;
	m_nNumSubMtls = nNumSubMtls;
	m_pMapDiffuse = pMapDif;
	m_SubMaterialList.resize(m_nNumSubMtls);
	m_fMaterialShine = fMatShine;
	m_fMaterialShineStrength = fMatShStrength;
	m_fMaterialSelfIllum = fMatSelfIllum;
	m_MaterialAmbient = matAmbient;
	m_MaterialDiffuse = matDiffuse;
	m_MaterialSpecular = matSpecular;
}

CMaterial::~CMaterial()
{
	if (m_pMapDiffuse != NULL)
	{
		delete m_pMapDiffuse;
		m_pMapDiffuse = NULL;
	}

	for (int i = 0; i < m_nNumSubMtls; i++)
	{
		delete m_SubMaterialList[i];
	}

	m_SubMaterialList.clear();
}

